﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.Location
{
    public class City:ICity
    {
        public int GetCityId(string cityName, ref Model.NutriLeafDBEntities context)
        {
            if (context.Cities.Where(p => p.CityName.CompareTo(cityName) == 0).Count() != 0)
            {
                return context.Cities.Where(p => p.CityName.CompareTo(cityName) == 0).First().CityID;
            }
            else
                return -1;
           
        }

        public void InsertCity(string cityName, string countryName, ref Model.NutriLeafDBEntities context)
        {
            Model.City city = new Model.City();
            city.CityName = cityName;
            Model.Country country = context.Countries.Where(p => p.Name.CompareTo(countryName) == 0).First();
            country.Cities.Add(city);
            context.SaveChanges();
        }

        public void InsertCity(string cityName, int countryId, ref Model.NutriLeafDBEntities context)
        {
            Model.City city = new Model.City();
            city.CityName = cityName;
            Model.Country country = context.Countries.Where(p => p.CountryID==countryId).First();
            country.Cities.Add(city);
            context.SaveChanges();
       
        }

        public void InsertCity(string cityName, Model.Country country, ref Model.NutriLeafDBEntities context)
        {
            Model.City city = new Model.City();
            city.CityName = cityName;
            Model.Country countries = context.Countries.Where(p => p.CountryID==country.CountryID).First();
            countries.Cities.Add(city);
            context.SaveChanges();
        }

        public void InsertCity(Model.City city, ref Model.NutriLeafDBEntities context)
        {
            context.Cities.AddObject(city);
            context.SaveChanges();
        }

        public List<Model.City> GetCitiesForACountry(string country, ref Model.NutriLeafDBEntities context)
        {
            return context.Countries.Where(p => p.Name.CompareTo(country) == 0).First().Cities.ToList();
        }

        public List<Model.City> GetCitiesForACountry(int countryId, ref Model.NutriLeafDBEntities context)
        {
            return context.Countries.Where(p => p.CountryID==countryId).First().Cities.ToList();
        }

        public List<Model.City> GetCitiesForACountry(Model.Country country, ref Model.NutriLeafDBEntities context)
        {
            return context.Countries.Where(p => p.Name.CompareTo(country.Name) == 0).First().Cities.ToList();
        }

        public void RemoveCity(string cityName, ref Model.NutriLeafDBEntities context)
        {
            throw new NotImplementedException();
        }

        public void RemoveCity(int cityId, ref Model.NutriLeafDBEntities context)
        {
            throw new NotImplementedException();
        }

        public void RemoveCity(Model.City city, ref Model.NutriLeafDBEntities context)
        {
            throw new NotImplementedException();
        }

        public Model.City GetCity(int id, ref Model.NutriLeafDBEntities context)
        {
            throw new NotImplementedException();
        }

        public Model.City GetCity(string cityName, ref Model.NutriLeafDBEntities context)
        {
            throw new NotImplementedException();
        }

        public void UpdateCity(Model.City city, ref Model.NutriLeafDBEntities context)
        {
            throw new NotImplementedException();
        }

        public void UpdateCity(int cityId, string cityName, int countryId, ref Model.NutriLeafDBEntities context)
        {
            throw new NotImplementedException();
        }
    }
}